import axios from "axios";
import { useEffect, useState } from "react";
import { encryptedData } from "../../../utils";
import { useAppSelector } from "../../../app/hooks";

export function useDoctorAwser() {
  const [sessionId, setSessionId] = useState<string>("");
  const [doctorId, setDoctorId] = useState<string>("");
  const userId = useAppSelector((state) => state.user.userInfo.userId);
  const doctorAwser = async ({ inquiryId }) => {
    return axios.post(
      "/api/health/doctor/inquiry/verify/v1/pushMessage",
      {
        inquiryId,
        content: "医生端未完成， 默认每次回复",
        type: 1,
        userId,
      },
      {
        headers: {
          doctorId,
          sessionId,
          "Content-Type": "application/x-www-form-urlencoded",
        },
      }
    );
  };
  useEffect(() => {
    const data = {
      email: "906446244@qq.com",
      pwd: encryptedData("123456"),
    };
    axios
      .post("/api/health/doctor/v1/login", data, {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
        },
      })
      .then((resp) => {
        setSessionId(resp.data.result.sessionId);
        setDoctorId(resp.data.result.doctorId);
      });
  }, []);
  return { sessionId, doctorId, doctorAwser };
}
